﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Windows.Forms;
using System.IO;

namespace Shoozla.DataModel.Helper
{
    public class TxtTraceListener : TextWriterTraceListener
    {
        public TxtTraceListener(string filename)
            :  base(filename)
        {
            if (!Trace.Listeners.Contains(this))
            {
                Trace.Listeners.Add(this);
            }
        }

        public override void Write(string o)
        {
            string TID = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString();
                 
            StringBuilder txt = new StringBuilder(DateTime.Now.ToLocalTime().ToShortTimeString());
            txt.Append("["+TID);
            for(int i=TID.Length;i<=4;i++)
                txt.Append("-");
            txt.Append("] | ");
            txt.Append(o);
            this.Writer.Write(txt);
        }

        public override void WriteLine(string o)
        {
            Write(o + Environment.NewLine);
        }
    }
}